package com.bsy.framework.ext

import java.security.MessageDigest
import java.security.NoSuchAlgorithmException

/**
 * Created by Lucy on 2023/10/18.
 * Copyright
 * 描述 :工具类
 */

/**
 * 给字符串拼接一个01尾缀
 * @return
 */
fun String?.date(): String = if (this == null) "" else "$this-01"
fun String?.data(): String = this ?: ""
fun Int?.data(): Int = this ?: 0
fun Boolean?.data(): Boolean = this ?: false
fun Number?.data(): Number = this ?: 0.0
fun Long?.data(): Long = this ?: 0L
fun Double?.data(): Double = this ?: 0.0
fun String.md5(): String {
    try {
        val md = MessageDigest.getInstance("MD5")
        val messageDigest = md.digest(this.toByteArray())
        val hexString = StringBuilder()
        for (b in messageDigest) {
            val hex = Integer.toHexString(0xFF and b.toInt())
            if (hex.length == 1) {
                hexString.append('0')
            }
            hexString.append(hex)
        }
        return hexString.toString()
    } catch (e: NoSuchAlgorithmException) {
        e.printStackTrace()
    }
    return ""
}
